package com.cntaiping.workutil.test;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Set;

/**
 * springboot读取启动jar传递的参数
 */
@Configuration
public class InitConfig {
    private static final Logger logger = LoggerFactory.getLogger(InitConfig.class);

    @Autowired
    private ApplicationArguments arguments;

    @Bean
    public void Init(){
        Set<String> optionNames = arguments.getOptionNames();

        if(optionNames != null && optionNames.size()>0){
            for (String optionName : optionNames) {
                String value = arguments.getOptionValues(optionName).get(0);

                logger.info("参数名：{}，参数值：{}",optionName,value);
            }
        }

    }


}
